import { useradd, usercount, userdelete, useredit, userinfo, userlist, userlogin } from "../../utils/request/api.js";
export default {
    userlogin_a( { commit }, payload) {
        userlogin(payload).then(res => {
            if (res.code == 200) {
                 commit('setuserlogin',res.list)
            }
            commit('setuserTitle',res.msg)
        })
    },
    userlist_a( { commit }, payload) {
        userlist(payload).then(res => {
            if (res.code == 200 && res.list) {
                 commit('setuserlist',res.list)
            }
        })
    },
    usercount_a({ commit }) {
        usercount().then(res => {
            commit('setusercount',res.list[0])
        })
    },
    useradd_a({ commit }, payload) {
        useradd(payload).then(res => {
             commit('setuserTitle', res)
        })
    },
    userdelete_a({ commit }, payload) {
        userdelete(payload).then(res => {
            //把操作成功变成删除成功
            if (res.code == 200) {
                commit('setuserTitle', {...res,msg:"删除成功"})
            }
        })
    },
    userinfo_a({ commit }, payload) {
        userinfo(payload).then(res => {
            //点击编辑的时候 直接把id添加到userinfo上
             commit('setuserinfo',{...res.list,id:payload})
        })
    },
    useredit_a({ commit }, payload) {
        useredit(payload).then(res => {
            //把操作成功变成修改成功
            commit('setuserTitle',{...res,msg:"修改成功"})
        })
    },
}